package be.novelfaces.webdriver;

import org.openqa.selenium.By;

import be.novelfaces.showcase.webdriver.util.ResourceBundleManager;
import be.novelfaces.showcase.webdriver.util.WaitForElementPresent;

public abstract class BasePage<T extends BasePage<?>> extends BaseElement {
	
	public BasePage() {
		initPage();
	}
	
	protected boolean arrivedAt() { 
		new WaitForElementPresent() {
			@Override
			public By getBy() {
				return By.id("contentHeader");
			}
		};
		return getWebDriver().findElement(By.id("contentHeader")).getText()
				.contains(getContentHeaderTitle());
	}

	@SuppressWarnings("unchecked")
	public final T assertArrivedAt() {
		if (!arrivedAt()) {
			throw new IllegalStateException(getContentHeaderTitle() + " is not the "
					+ getClass().getSimpleName() + " page");
		}
		return (T) this;
	}
	
	public String getProperty(String key) {
		return ResourceBundleManager.getResourceBundle().getProperty(key);
	}

	protected abstract String getContentHeaderTitle();

	protected abstract void initPage();

}
